// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: GHZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : object.timer
private alias object.value1 : object.index

private alias object.value2 : object.drawX
private alias object.value3 : object.drawY
private alias object.value4 : object.letter
private alias object.value5 : object.charamount
private alias object.value6 : object.boxYpos

public value BoxPositionY = 0;
public value CharacterTalking = 0;
public value TextActive = 0;
public value CutsceneActive = 0;

public alias saveRAM[286] : saved.language


reserve function TextDrawing

function TextDrawing
	temp0 = object.drawX
	temp1 = object.charamount
	while temp1 > 0
	// Get the actual character at the current char pos
	GetTextInfo(object.letter, 1, TEXTINFO_TEXTDATA, Object.Index, ArrayPos0)

	Object.Frame = 0
	
	// Take uppercase letters and turn them into a matching Sprite Frame
	if object.letter > 64
		if object.letter < 91
			Object.Frame  = object.letter
			Object.Frame -= 64
		end if
	end if
	
	// Take lowercase letters and turn them into a matching Sprite Frame
	if object.letter > 96
		if object.letter < 123
			Object.Frame  = object.letter
			Object.Frame -= 96
		end if
	end if

		//ASCII Table required!
		switch object.letter
			case 33	//!
				DrawSpriteScreenFX(37, FX_INK, object.drawX, object.drawY)
				ArrayPos0++
				temp1--
				object.drawX += 0x8
				break		
			case 63	//?
				DrawSpriteScreenFX(38, FX_INK, object.drawX, object.drawY)
				ArrayPos0++
				temp1--
				object.drawX += 0x8
				break					
			case 42
				DrawSpriteScreenFX(27, FX_INK, object.drawX, object.drawY)
				ArrayPos0++
				temp1--
				object.drawX += 0x8
				break
			case 42
				// Notably, the space character (32) is skipped over here, as it shouldn't draw anything
				

				DrawSpriteScreenFX(27, FX_INK, object.drawX, object.drawY)
				

				// Move to the next letter
				ArrayPos0++
				
				// And decrease the remaining letter count, as well
				temp1--
				
				// Each letter should be spaced 8 pixels apart
				object.drawX += 0x8
				break
			case 64	//@	LINE SKIPPER
				object.drawY += 16
				object.drawX = temp0
			

				// Move to the next letter
				ArrayPos0++
				
				// And decrease the remaining letter count, as well
				temp1--
			break
			default
			// Notably, the space character (32) is skipped over here, as it shouldn't draw anything
			

			DrawSpriteScreenFX(Object.Frame, FX_INK, object.drawX, object.drawY)

			// Move to the next letter
			ArrayPos0++
			
			// And decrease the remaining letter count, as well
			temp1--
			
			// Each letter should be spaced 8 pixels apart
			object.drawX += 0x8
			break
		end switch
	loop
end function

//if being stupid was a job

event ObjectMain

	if object[6].state != 2
		TextActive = 1
		object.timer = 0
		object.charamount = 0
	else
		object.alpha = 255
		GetTextInfo(temp0, 1, TEXTINFO_TEXTSIZE, Object.Index, 0)
		if object.charamount == temp0
			object.timer++
			if object.timer == 150
				object.timer = 0
			end if
		else
			object.charamount++
		end if
	end if

	Object.Index = Object[6].Value1

end event

event ObjectDraw

	object.inkEffect = INK_ALPHA

	ArrayPos0 = 0	//starting letter

	object.drawY = 75
	
	temp3 = screen.xsize
	temp3 -= 160
	object.drawX = temp3

	CallFunction(TextDrawing)
	
	if object.state >= 13
		DrawRect(0, 0, screen.xsize, screen.ysize, color7, color7, color7, 255)

		temp1 = screen.xcenter

		DrawSpriteScreenFX(39, FX_INK, temp1, screen.ycenter)

	end if

end event

event ObjectStartup
	LoadSpriteSheet("FNAF/Objects1.gif")
	switch saved.language
		case 0
			LoadTextFile(1, "Data/Game/Tutorial.txt")
		break
		case 1
			LoadTextFile(1, "Data/Game/Portuguese/Tutorial.txt")
		break
		case 2
			LoadTextFile(1, "Data/Game/TutorialSP.txt")
		break
		case 3
			LoadTextFile(1, "Data/Game/French/TutorialFR.txt")
		break		
	end switch
	
	SpriteFrame(0, 0, 0, 0, 0, 0)	//0 the bar

	// #1 -> #26 - Alphabet
	// (Using loops to automate Sprite Framing)

	//not related too stuff in objectdraw

	//temp7: starting ypos, progresses by 17 and stops before 100, because theres only 3 rows
	//temp6: starting xpos, the letter A
	temp1 = 49
	while temp1 < 100
		temp0 = 549
		while temp0 < 648
			SpriteFrame(-3, -6, 8, 16, temp0, temp1)
			temp0 += 9
		loop
		temp1 += 17
	loop

	BoxPositionY = 0
	CharacterTalking = 0
	TextActive = 0
	CutsceneActive = 0	

	//undertale
	SpriteFrame(-3, -6, 8, 16, 513, 100) //27

	//undertale
	SpriteFrame(-180, -6, 65, 51, 513, 117) //35 slender man icon

	SpriteFrame(-160, -22, 320, 80, 26, 683) //36 slender man icon	
	
	//undertale
	SpriteFrame(-3, -6, 8, 16, 522, 100) //37
	
	
	//undertale
	SpriteFrame(-3, -6, 8, 16, 531, 100) //38

	//undertale
	SpriteFrame(-130, -128, 256, 256, 2, 766) //39

	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[8].Type = TypeName[Message Text]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[8].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[8].DrawOrder = 5

end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("IIZ/Objects1.gif")
	SpriteFrame(0, 0, 64, 64, 153, 154)
end event
